﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="list.aspx.cs" Inherits="jnlamp.Web.mobile.list" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
    <title>杀虫灯系统平台</title>
    <link rel="stylesheet" type="text/css" href="easyui/themes/metro/easyui.css" />
    <link rel="stylesheet" type="text/css" href="easyui/themes/mobile.css" />
    <link rel="stylesheet" type="text/css" href="easyui/themes/icon.css" />
    <script type="text/javascript" src="easyui/jquery.min.js"></script>
    <script type="text/javascript" src="easyui/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="easyui/jquery.easyui.mobile.js"></script>
    <script src="easyui/locale/easyui-lang-zh_CN.js"></script>
    <script src="../Script/datetime.js"></script>
    <script src="js/mobile.js"></script>
    <script type="text/javascript">
        var uid = 0;
        var gwid = "";
        var add = "";
        var uname = "";
        var qxchs;
        var level = 0;
        var bid = 0;
        $(function () {
            bid = getUrlParam("bid");
            InitGird();
            initMenu();
        });
        function InitGird() {
            $('#tt').datagrid({
                title: '设备运行状态', //表格标题
                url: '../lampinfo/GetScd.ashx', //请求数据的页面
                sortName: 'inputTime', //排序字段
                idField: '', //标识字段,主键
                iconCls: '', //标题左边的图标
                width: '100%', //宽度
                height: 100,
                nowrap: true, //是否换行，True 就会把数据显示在一行里
                striped: true, //True 奇偶行使用不同背景色
                collapsible: false, //可折叠
                sortOrder: 'desc', //排序类型
                remoteSort: true, //定义是否从服务器给数据排序
                fitColumns: false,
                singleSelect: true,
                method: 'post',
                columns: [[//
                   { title: '网关号', field: 'gwid', width: 80 },
                   { title: '灯号', field: 'lampid', width: 80 },
                   {
                       title: '状态', field: 'lampstatus', width: 60, formatter: function (value, row, index) {
                           //if (value == '3')
                           //    return '失联';
                           //else if (value == '2')
                           //    return '<img src="/images/bullet_red.png" height="16" width="16"/>';
                           //else
                               return '<img src="/images/bullet_green.png" height="16" width="16" />';
                       }
                   },
                    { title: '电池板电压', field: 'dcb_v', width: 80 },
                    { title: '蓄电池电压', field: 'xdc_v', width: 80 },
                    {
                        title: '电池板电流', field: 'dcb_i', width: 80, formatter: function (value, row, index) {
                            if (value == "True")
                                return '有电流';
                            else
                                return '无电流';
                        }
                    },
                    {
                        title: '电流', field: 'scd_i', width: 60, formatter: function (value, row, index) {
                            if (value == "True")
                                return '有电流';
                            else
                                return '无电流';
                        }
                    },
                    {
                        title: '电池板状态', field: 'dcb_s', width: 80, formatter: function (value, row, index) {
                            if (value == "1")
                                return '正常';
                            else
                                return '异常或被盗';
                        }
                    },
                    {
                        title: '开闭状态', field: 'scd_s', width: 60, formatter: function (value, row, index) {
                            if (value == "1")
                                return '<img src="/images/bullet_green.png" height="16" width="16" />';
                            else
                                return '<img src="/images/bullet_red.png" height="16" width="16"/>';
                        }
                    },
                    { title: '开闭时长', field: 'scd_t', width: 60 },
                    {
                        title: '是否上传数据', field: 'datetime', width: 90, formatter: function (value, row, index) {
                            //if (value == "" || value == null)
                            //    return '<img src="/images/bullet_red.png" height="16" width="16"/>';
                            //else
                                return '<img src="/images/bullet_green.png" height="16" width="16" />';
                        }
                    },
                    {
                        title: '上传时间', field: 'inputTime', width: 150, formatter: function (value, row, index) {
                            if (value != "") {

                                if (value.indexOf("-") != -1)
                                    value = value.replace(/-/g, "/")
                                return new Date(value).pattern("yyyy年M月d日 hh:mm:ss");
                            }
                        }
                    },
                    { title: '生产厂商', field: 'mname', width: 150 }
                ]
                ],                
                onLoadSuccess: function (data) {
                    var info = "";
                    info = "共有灯" + data.total + "台。";
                    //var sl = [];
                    //var sh = [];
                    //var state = "";
                    //var mname = "";
                    //var slnum = 0;
                    //var shnum = 0;
                    //$.each(data.rows, function (k, v) {
                    //    state = v["lampstatus"];
                    //    if (state == '3') {
                    //        slnum = slnum + 1;
                    //        mname = v["mname"];
                    //        if (sl[mname]) {
                    //            sl[mname] = sl[mname] + 1;
                    //        }
                    //        else {
                    //            sl[mname] = 1;
                    //        }
                    //    }
                    //    else if (state == '2') {
                    //        shnum = shnum + 1;
                    //        mname = v["mname"];
                    //        if (sh[mname]) {
                    //            sh[mname] = sh[mname] + 1;
                    //        }
                    //        else {
                    //            sh[mname] = 1;
                    //        }
                    //    }

                    //});
                    //var outputsl = "";
                    //for (var key in sl) {
                    //    if (sl.hasOwnProperty(key))
                    //        if (outputsl == "") {
                    //            outputsl = key + '(' + sl[key] + ')';
                    //        }
                    //        else {
                    //            outputsl += "、" + key + '(' + sl[key] + ')';
                    //        }
                    //}
                    //var outputsh = "";
                    //for (var key in sh) {
                    //    if (sh.hasOwnProperty(key))
                    //        if (outputsh == "") {
                    //            outputsh = key + '(' + sh[key] + ')';
                    //        }
                    //        else {
                    //            outputsh += "、" + key + '(' + sh[key] + ')';
                    //        }
                    //}
                    //if (slnum > 0)
                    //    info = info + "失联" + slnum + "台，失联详情：" + outputsl + "。";
                    //if (shnum > 0)
                    //    info = info + "损坏" + shnum + "台，损坏详情：" + outputsh + "。";
                    $('#myinfo').html(info);
                    //$('#tt').datagrid("getPanel").panel('setTitle', '设备运行状态:' + info);
                },
                onClickRow: function (rowIndex, rowData) {
                    var dl = "";
                    if (rowData.dcb_i == "True")
                        dl = '有电流';
                    else
                        dl = '无电流';
                    var zt = "";
                    if (rowData.dcb_s == "1")
                        zt = '正常';
                    else
                        zt = '异常或被盗';

                    var scd = "";
                    if (rowData.scd_s == "0")
                        scd = "开";
                    else
                        scd = "关";
                    yjfx = "网关ID" + rowData.gwid + "灯ID" + rowData.lampid + ",在" + rowData.inputTime + ',电池板电压' + rowData.dcb_v + ',蓄电池电压' + rowData.xdc_v + ',电池板' + dl + ',电池板状态' + zt + ',杀虫灯' + scd;
                    //$('#yjfx').text(yjfx);
                    $('#mmark').val(yjfx);
                    $.mobile.go('#sendalarm');
                },
                queryParams: { "action": "queryb", "bid": bid },
                pagination: true, //是否开启分页
                pageNumber: 1, //默认索引页
                pageSize: 20, //默认一页数据条数
                rownumbers: true
            });
        }

        //增加查询参数，重新加载表格  
        function reloadgrid() {
            var queryParams = $('#tt').datagrid('options').queryParams;
            //getQueryParams(queryParams);
            $('#tt').datagrid('options').queryParams = queryParams;
            $("#tt").datagrid('reload');
        }
        function showAlarm() {
            //$('#dlg').dialog('open').dialog('setTitle', '预警信息发送');
            InitSendUser();
            $('#mmark').val(yjfx);
        }
        function InitSendUser() {
            $('#senduser').combotree({
                url: '../userinfo/GetLinker.ashx?action=queryt',
                multiple: true,
                width: 300,
                valueField: 'id',
                textField: 'text',
                //panelHeight: 'auto'
                panelHeight: 160

            });
            $('#mmark').ckeditor();           

        }        
        function sendAlarm() {            
            var f = $('#myalarm');
            var uids = $('#senduser').combotree('getValues');
            var alevel = $('#alarmlevel').val();
            $.messager.progress();
            f.form('submit', {
                url: "../info/GetInfo.ashx?action=adds&uid=" + uids + "&alarmclass=",
                onSubmit: function () {
                    var isval = $(this).form('validate');
                    if (isval == false) $.messager.progress('close');
                    return isval;
                },
                success: function (result) {
                    $.messager.progress('close');
                    if (result.indexOf("T") == 0) {
                        $.mobile.go('#mylist');
                        $.messager.alert("提示", "恭喜您，信息发送成功", "info");
                    }
                    else if ((result.indexOf("F") == 0)) {
                        $.messager.alert("提示", "发送失败，请重新操作！", "info");
                        return;
                    }
                    else if ((result.indexOf("L") == 0)) {
                        $.messager.alert("提示", "长时间没有操作，请重新登录！", "info");
                        top.location = '/index.aspx';
                        return;
                    }
                }
            });
        }

    </script>
</head>
<body>
     <div id="mylist" class="easyui-navpanel">

        <table id="tt" data-options="header:'#hh',singleSelect:true,border:false,fit:true,fitColumns:true,scrollbarSize:0">
            
        </table>
        <div id="hh">
            <div class="m-toolbar">
                <div class="m-title"><span id="myinfo" style="line-height:20px;">灯信息</span></div>
            </div>
        </div>
        <footer>
            <div class="m-buttongroup m-buttongroup-justified" style="width: 100%">
                <a  id="mymain" href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-large-chart',size:'large',iconAlign:'top',plain:true">查看设备</a>
                <a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-large-clipart',size:'large',iconAlign:'top',plain:true">Clip Art</a>
                <a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-large-shapes',size:'large',iconAlign:'top',plain:true">Shapes</a>
                <a id="myexist" href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-large-smartart',size:'large',iconAlign:'top',plain:true">退出</a>
            </div>
        </footer>

    </div>
    
</body>
</html>
